<?php

namespace App\Providers;

use Carbon\Carbon;
use Illuminate\Support\Facades\Validator;
use Illuminate\Support\Facades\App;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\ServiceProvider;

class AppServiceProvider extends ServiceProvider
{
    /**
     * Register any application services.
     */
    public function register(): void
    {
        //
    }

    /**
     * Bootstrap any application services.
     */
    public function boot(): void
    {
        
        Carbon::setLocale('zh-CN');
        if (App::environment() != 'product') {
            DB::listen(function ($query) {
                Log::channel('sqlTest')->info($query->sql);
                Log::channel('sqlTest')->info($query->bindings);
                Log::channel('sqlTest')->info($query->time);
                // $query->sql
                // $query->bindings
                // $query->time
            });
        }
        // 添加自定义验证规则,允许字母和数字
        Validator::extend('allow_letter_num', function ($attribute, $value, $parameters, $validator) {
            return is_string($value) && preg_match('/^[a-zA-Z0-9]+$/u', $value);
        });
    }
}
